
public class Board {

	
	private char[][] board = null;
	
	public static final char SHIP = 'o';
	public static final char FREE = ' ';
	public static final char TRIED = '-';
	public static final char STROKE = '*';
	public static final char SUNK = 'X';
	
	
	public Board(int size) {
		board = new char[size][];
		for (int i = 0; i < board.length; i++) {
			board[i] = new char[size];
			for (int j = 0; j < board[i].length; j++) {
				board[i][j] = FREE;
			}
		}
		for (int i = 0; i < board.length; i++) {
			board[i][0] = TRIED;
			board[i][size - 1] = TRIED; 
		}
		for (int i = 0; i < board.length; i++) {
			board[0][i] = TRIED;
			board[size - 1][i] = TRIED; 
		}
	}
	
	public int size() {
		return board.length;
	}
	
	public char getField(int x , int y) {
		return board[x][y];
	}
	
	public void setField(int x, int y, char value) {
		board[x][y] = value;
	}
	
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		sb.append("  ");
		for (int i = 1; i < board.length - 1; i++) {
			sb.append(String.format("%1$2d", i));
			
		}
		sb.append("\n");
		for (int i = 1; i < board.length - 1; i++) {
			sb.append(String.format("%1$2d", i));
			for (int j = 1; j < board[i].length - 1; j++) {
				sb.append(" " + board[i][j]);
			}
			sb.append(String.format("%1$2d", i));
			sb.append("\n"); //enter
		}
		sb.append("  ");
		for (int i = 1; i < board.length - 1; i++) {
			sb.append(String.format("%1$2d", i));
			
		}
		sb.append("\n");
		return sb.toString();
	}
	
}

